package com.ruoyi.chambers.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.flats.domain.Flats;
import com.ruoyi.flats.service.IFlatsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.chambers.domain.Chambers;
import com.ruoyi.chambers.service.IChambersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 房间管理Controller
 *
 * @author ruoyi
 * @date 2024-10-15
 */
@RestController
@RequestMapping("/chambers/chambers")
public class ChambersController extends BaseController
{
    @Autowired
    private IChambersService chambersService;
    private IFlatsService flatsService;

    /**
     * 查询房间管理列表
     */
    @PreAuthorize("@ss.hasPermi('chambers:chambers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Chambers chambers)
    {
        startPage();
        List<Chambers> list = chambersService.selectChambersList(chambers);
        return getDataTable(list);
    }

    /**
     * 导出房间管理列表
     */
    @PreAuthorize("@ss.hasPermi('chambers:chambers:export')")
    @Log(title = "房间管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Chambers chambers)
    {
        List<Chambers> list = chambersService.selectChambersList(chambers);
        ExcelUtil<Chambers> util = new ExcelUtil<Chambers>(Chambers.class);
        util.exportExcel(response, list, "房间管理数据");
    }

    /**
     * 获取房间管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('chambers:chambers:query')")
    @GetMapping(value = "/{chamberId}")
    public AjaxResult getInfo(@PathVariable("chamberId") Long chamberId)
    {
        return success(chambersService.selectChambersByChamberId(chamberId));
    }

    /**
     * 新增房间管理
     */
    @PreAuthorize("@ss.hasPermi('chambers:chambers:add')")
    @Log(title = "房间管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Chambers chambers)
    {
        return toAjax(chambersService.insertChambers(chambers));
    }

    /**
     * 修改房间管理
     */
    @PreAuthorize("@ss.hasPermi('chambers:chambers:edit')")
    @Log(title = "房间管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Chambers chambers)
    {
        return toAjax(chambersService.updateChambers(chambers));
    }

    /**
     * 删除房间管理
     */
    @PreAuthorize("@ss.hasPermi('chambers:chambers:remove')")
    @Log(title = "房间管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chamberIds}")
    public AjaxResult remove(@PathVariable Long[] chamberIds)
    {
        return toAjax(chambersService.deleteChambersByChamberIds(chamberIds));
    }
    @GetMapping("/flatOptions")
    public AjaxResult getFlatOptions()
    {
         List<Flats> list = flatsService.selectFlatsList(new Flats());
         return AjaxResult.success(list);
    }

}
